package com.ruoyi.common.net.mqtt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.stereotype.Service;

/**
 * @author xumh
 * @title: MessageSubscribe
 * @description: TODO
 * @date 2024/12/1815:00
 */
@Service
public class MessageSubscribe {
    @Autowired(required = false)
    private MessageProducer messageProducer;

    public MessageSubscribe() {
    }

    public void subscribe(String... topics) {
        MqttPahoMessageDrivenChannelAdapter adapter = (MqttPahoMessageDrivenChannelAdapter)this.messageProducer;
        adapter.addTopic(topics);
    }

    public void unsubscribe(String... topics) {
        MqttPahoMessageDrivenChannelAdapter adapter = (MqttPahoMessageDrivenChannelAdapter)this.messageProducer;
        adapter.removeTopic(topics);
    }
}
